#include<bits/stdc++.h>
using namespace std;
int n,m,k,a,b,c,d;
int id(int x,int y)
{
	return (x - 1) * m + y;
}
set<pair<int,int> > t[600011];
char mp[6000011];
int dis[6000011];
pair<int,int> dui[6000011];
void Del(int p,pair<int,int> x,int l,int r)
{
	t[p].erase(x);
	if(l == r)
		return;
	int mid = l + r >> 1;
	if(x.second <= mid)
		Del(p << 1,x,l,mid);
	else
		Del(p << 1 | 1,x,mid + 1,r);
}
void Add(int p,pair<int,int> x,int l,int r)
{
	t[p].insert(x);
	if(l == r)
		return;
	int mid = l + r >> 1;
	if(x.second <= mid)
		Add(p << 1,x,l,mid);
	else
		Add(p << 1 | 1,x,mid + 1,r);
}
pair<int,int> st[6000011];
int top;
void ask(int p,int l,int r)
{
	auto i = t[p].lower_bound({l,0});
	while(i != t[p].end() && (*i).first <= r)
		st[++top] = *i,i++; 
}
void Ask(int p,int l,int r,int u,int d,int ll,int rr)
{
	auto i = t[p].lower_bound({u,0});
	if(i == t[p].end() || (*i).first > d)
		return;
	if(l <= ll && rr <= r)
		return ask(p,u,d);
	int mid = ll + rr >> 1;
	if(l <= mid)
		Ask(p << 1,l,r,u,d,ll,mid);
	if(mid < r)
		Ask(p << 1 | 1,l,r,u,d,mid + 1,rr);
}
int q[12000011],l = 6000005,r = 6000005;
const int inf = 0x3f3f3f3f;
bool svd[6000011];
void Solve(int p)
{
	if(svd[p])
		return;
	svd[p] = 1;
	int x = dui[p].first,y = dui[p].second;
//	cerr << x << "," << y << ":" << dis[p] << "\n";
	top = 0;
	Ask(1,y - k - 1,y + k + 1,x - k - 1,x + k + 1,1,m);
	for(int i = 1;i <= top;i++)
	{
		int a = st[i].first,b = st[i].second;
		if(abs(a - x) + abs(b - y) <= 2 * k && (min(abs(a - x),abs(b - y)) < k || mp[id(a,b)] == '.'))
		{
//		cerr << "||-> " << a << "," << b << "\n";
			Del(1,st[i],1,m);
			int x = id(a,b);
			if(dis[x] > dis[p] + 1)
				dis[q[r++] = x] = dis[p] + 1;
		}
	}
	if(x > 1 && mp[id(x - 1,y)] == '.' && dis[id(x - 1,y)] > dis[p])
		dis[q[--l] = id(x - 1,y)] = dis[p];
	if(y > 1 && mp[id(x,y - 1)] == '.' && dis[id(x,y - 1)] > dis[p])
		dis[q[--l] = id(x,y - 1)] = dis[p];
	if(x < n && mp[id(x + 1,y)] == '.' && dis[id(x + 1,y)] > dis[p])
		dis[q[--l] = id(x + 1,y)] = dis[p];
	if(y < m && mp[id(x,y + 1)] == '.' && dis[id(x,y + 1)] > dis[p])
		dis[q[--l] = id(x,y + 1)] = dis[p];
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	freopen("stamp.in","r",stdin);
	freopen("stamp.out","w",stdout);
	cin >> n >> m >> k >> a >> b >> c >> d;
	for(int i = 1;i <= n;i++)
		for(int j = 1;j <= m;j++)
			cin >> mp[id(i,j)],Add(1,dui[id(i,j)] = {i,j},1,m);
	memset(dis,0x3f,sizeof(dis));
	int S = id(a,b),T = id(c,d);
	dis[q[r++] = S] = 0,Del(1,dui[S],1,m);
	Solve(S);
	while(l <= r)
	{
		int p = q[l++];
		Solve(p);
	}
	cout << dis[T];
	return 0;
}
